home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / python2.4 / test / test_xmlrpc.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2005-10-18  |  4KB  |  96 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. import sys
  5. import unittest
  6. import xmlrpclib
  7. from test import test_support
  8.  
  9. try:
  10.     unicode
  11. except NameError:
  12.     have_unicode = False
  13.  
  14. have_unicode = True
  15. alist = [
  16.     {
  17.         'astring': 'foo@bar.baz.spam',
  18.         'afloat': 7283.4300000000003,
  19.         'anint': 2 ** 20,
  20.         'ashortlong': 0x2L,
  21.         'anotherlist': [
  22.             '.zyx.41'],
  23.         'abase64': xmlrpclib.Binary('my dog has fleas'),
  24.         'boolean': xmlrpclib.False,
  25.         'unicode': u'\xe4\x80\x80\xe6\x80\x80\xe8\x80\x80',
  26.         u'ukey\xe4\x80\x80': 'regular value' }]
  27.  
  28. class XMLRPCTestCase(unittest.TestCase):
  29.     
  30.     def test_dump_load(self):
  31.         self.assertEquals(alist, xmlrpclib.loads(xmlrpclib.dumps((alist,)))[0][0])
  32.  
  33.     
  34.     def test_dump_big_long(self):
  35.         self.assertRaises(OverflowError, xmlrpclib.dumps, (0x2L ** 99,))
  36.  
  37.     
  38.     def test_dump_bad_dict(self):
  39.         self.assertRaises(TypeError, xmlrpclib.dumps, ({
  40.             (1, 2, 3): 1 },))
  41.  
  42.     
  43.     def test_dump_big_int(self):
  44.         if sys.maxint > 0x2L ** 31 - 1:
  45.             self.assertRaises(OverflowError, xmlrpclib.dumps, (int(0x2L ** 34),))
  46.         
  47.  
  48.     
  49.     def test_dump_none(self):
  50.         value = alist + [
  51.             None]
  52.         arg1 = (alist + [
  53.             None],)
  54.         strg = xmlrpclib.dumps(arg1, allow_none = True)
  55.         self.assertEquals(value, xmlrpclib.loads(strg)[0][0])
  56.         self.assertRaises(TypeError, xmlrpclib.dumps, (arg1,))
  57.  
  58.     
  59.     def test_default_encoding_issues(self):
  60.         utf8 = "<?xml version='1.0' encoding='iso-8859-1'?>\n                  <params>\n                    <param><value>\n                      <string>abc \x95</string>\n                      </value></param>\n                    <param><value>\n                      <struct>\n                        <member>\n                          <name>def \x96</name>\n                          <value><string>ghi \x97</string></value>\n                          </member>\n                        </struct>\n                      </value></param>\n                  </params>\n                  "
  61.         old_encoding = sys.getdefaultencoding()
  62.         setdefaultencoding_existed = hasattr(sys, 'setdefaultencoding')
  63.         reload(sys)
  64.         sys.setdefaultencoding('iso-8859-1')
  65.         
  66.         try:
  67.             (s, d) = ()
  68.             m = xmlrpclib.loads(utf8)
  69.         finally:
  70.             sys.setdefaultencoding(old_encoding)
  71.             if not setdefaultencoding_existed:
  72.                 del sys.setdefaultencoding
  73.             
  74.  
  75.         items = d.items()
  76.         if have_unicode:
  77.             self.assertEquals(s, u'abc \xc2\x95')
  78.             self.assert_(isinstance(s, unicode))
  79.             self.assertEquals(items, [
  80.                 (u'def \xc2\x96', u'ghi \xc2\x97')])
  81.             self.assert_(isinstance(items[0][0], unicode))
  82.             self.assert_(isinstance(items[0][1], unicode))
  83.         else:
  84.             self.assertEquals(s, 'abc \xc2\x95')
  85.             self.assertEquals(items, [
  86.                 ('def \xc2\x96', 'ghi \xc2\x97')])
  87.  
  88.  
  89.  
  90. def test_main():
  91.     test_support.run_unittest(XMLRPCTestCase)
  92.  
  93. if __name__ == '__main__':
  94.     test_main()
  95.  
  96.